<template>
  <a-spin :spinning="confirmLoading" style="margin: 5%;">
    <j-form-container>
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="活动名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hdmc">
              <a-input v-model="model.hdmc" placeholder="请输入活动名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入活动地点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所在地区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area">
              <j-dict-select-tag type="list" v-model="model.area" dictCode="sys_area" placeholder="请选择所在地区" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="start">
              <j-date placeholder="请选择开始时间" v-model="model.start"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="end">
              <j-date placeholder="请选择结束时间" v-model="model.end"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入联系方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优待详情" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detail">
              <j-editor v-model="model.detail" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="封面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl">
              <j-image-upload isMultiple  v-model="model.imageUrl" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="身份证正面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl">
              <j-image-upload v-model="model.imageSfzzm" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="身份证反面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl">
              <j-image-upload v-model="model.imageSfzfm" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl">
              <j-image-upload v-model="model.imageYyzz" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="承诺书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl">
              <j-image-upload v-model="model.imageCns" ></j-image-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    
    <a-button type="primary" @click="submitForm" block>提交</a-button>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SysActivitiesAdd',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          hdmc:'',
          address:'',
          area:'',
          start:'',
          end:'',
          phone:'',
          detail:'',
          imageSfzzm:'',
          imageSfzfm:'',
          imageYyzz:'',
          imageCns:''
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          hdmc:[{required: true, message: '请输入活动名称!' }],
          address:[{required: true, message: '请输入具体地址!' }],
          area:[{required: true, message: '请选择所在地区!' }],
          start:[{required: true, message: '请选择开始时间!' }],
          end:[{required: true, message: '请选择结束时间!' }],
          phone:[{required: true, message: '请输入联系方式!' }],
          detail:[{required: true, message: '请输入活动详情!' }],
          imageSfzzm:[{required: true, message: '请上传身份证正面!' }],
          imageSfzfm:[{required: true, message: '请上传身份证反面!' }],
          imageYyzz:[{required: true, message: '请上传营业执照!' }],
          imageCns:[{required: true, message: '请上传承诺书!' }]  
        },
        url: {
          add: "/veterans/sysActivities/add"
        }
      }
    },
    methods: {
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                location. reload();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      }
    }
  }
</script>